package getsubs.model;

import java.io.File;
import java.io.IOException;

public class SubDownloader {
    private final SubtitleFinder finder;
    private final EpisodeInfoGuesser guesser;

    public SubDownloader(SubtitleFinder finder, EpisodeInfoGuesser guesser) {
        this.finder = finder;
        this.guesser = guesser;
    }

    public void downloadSubtitlesFor(File needyClip) throws IOException {
        EpisodeInfo episodeInfo = guesser.guessFromFilename(needyClip.getName());
        File clipDir = needyClip.getParentFile();
        
        for(Subtitle sub:finder.findSubtitlesFor(episodeInfo.getShowName(),
                                                 episodeInfo.getSeason(),
                                                 episodeInfo.getEpisode())) {
            sub.downloadTo(clipDir);
        }
    }
    
}
